#include "team.h"
team::team() {

}
team::team(QString name) {
	this->name = name;
	memset(this->val, 0, sizeof(val));
}
team::~team() {

}
QString team::getName() {
	return name;
}
void team::setName(QString name) {
	this->name = name;
}
int* team::getVal() {
	return this->val;
}
void team::swapVal(int m,int n) {
	int temp;
	temp = val[m];
	val[m] = val[n];
	val[n] = temp;
}


void team::setVal(int index, int value) {
	this->val[index] = value;
}

void team::addVal(int index, int value) {
	this->val[index] += value;
}
int team::sumVal(int index) {
	int sum = 0;
	for (int i = 0; i < index; i++) {
		sum += this->val[i];
	}
	return sum;
	//return this->val[index];
}

QJsonObject team::toJsonObject() {
	QJsonObject obj;

	// 序列化基类属性
	obj["name"] = getName();

	// 序列化数组值
	const int* values = getVal();
	QJsonArray valArray;
	for (int i = 0; i < teamNum; i++) {
		valArray.append(values[i]);
	}
	obj["val"] = valArray;

	return obj;
}